package com.rms.service.impl;

import java.util.Date;
import java.util.List;

import com.rms.dao.IDinnerTableDao;
import com.rms.dao.impl.DinnerTableDao;
import com.rms.entity.DinnerTable;

import com.rms.service.IDinnerTableService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class DinnerTableService implements IDinnerTableService{


	@Resource
	IDinnerTableDao dinnerTableDao;

	@Override
	public void add(DinnerTable dt) {
		dinnerTableDao.add(dt);
	}

	@Override
	public void delete(int id) {
		dinnerTableDao.delete(id);
	}

	@Override
	public void updata(DinnerTable dt) {
		dinnerTableDao.updata(dt);
	}

	@Override
	public List<DinnerTable> query(String keyword) {
		return dinnerTableDao.query(keyword);
	}
	
	@Override
	public List<DinnerTable> query() {
		return dinnerTableDao.query();
	}
	
	@Override
	public DinnerTable changeState(int id) {
		DinnerTable table = dinnerTableDao.findById(id);
		
		int status = table.getTableStatus();
		if(status==0){
			status=1;
			Date date = new Date();
			table.setOrderDate(date);
		}else if(status==1){
			status=0;
			table.setOrderDate(null);
		}
		table.setTableStatus(status);
		dinnerTableDao.updata(table);
		return table;
	}
	
	@Override
	public DinnerTable findById(int id) {
		return dinnerTableDao.findById(id);
	}
	@Override
	public void quitTable(int id) {
		dinnerTableDao.quitTable(id);
	}
}
